﻿using System;
using System.IO;
using System.Threading.Tasks;

namespace DistTest
{
    public class FileLogging : ILogging
    {
        private readonly string filename = "log.txt";

        public void Error(string content)
        {
            using (var writer = new StreamWriter(filename, true))
            {
                writer.WriteLine($"{DateTime.Now.ToString("hh:mm:ss")} [Error] {content}");
            }
        }

        public Task ErrorAsync(string content)
        {
            using (var writer = new StreamWriter(filename, true))
            {
                return writer.WriteLineAsync($"{DateTime.Now.ToString("hh:mm:ss")} [Error] {content}");
            }
        }

        public void Info(string content)
        {
            using (var writer = new StreamWriter(filename, true))
            {
                writer.WriteLine($"{DateTime.Now.ToString("hh:mm:ss")} [Info ] {content}");
            }
        }

        public Task InfoAsync(string content)
        {
            using (var writer = new StreamWriter(filename, true))
            {
                return writer.WriteLineAsync($"{DateTime.Now.ToString("hh:mm:ss")} [Info ] {content}");
            }
        }

        public void Log(string content)
        {
            using (var writer = new StreamWriter(filename, true))
            {
                writer.WriteLine($"{DateTime.Now.ToString("hh:mm:ss")} [Log  ] {content}");
            }
        }

        public Task LogAsync(string content)
        {
            using (var writer = new StreamWriter(filename, true))
            {
                return writer.WriteLineAsync($"{DateTime.Now.ToString("hh:mm:ss")} [Log  ] {content}");
            }
        }

        public void Warn(string content)
        {
            using (var writer = new StreamWriter(filename, true))
            {
                writer.WriteLine($"{DateTime.Now.ToString("hh:mm:ss")} [Warn ] {content}");
            }
        }

        public Task WarnAsync(string content)
        {
            using (var writer = new StreamWriter(filename, true))
            {
                return writer.WriteLineAsync($"{DateTime.Now.ToString("hh:mm:ss")} [Warn ] {content}");
            }
        }
    }
}
